﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using Microsoft.Practices.EnterpriseLibrary.Data;
using IBM.Data.DB2;


namespace WorkTool
{
	public class DataAccess
	{
		private string ConnectionString = "";

		public DataAccess(string connectionString)
		{
			ConnectionString = connectionString;
		}

		public DataTable ReturnDB2New(string query)
		{
			DataSet ds = new DataSet();
			using (DB2Connection conn = new DB2Connection(ConnectionString))
				using (DB2DataAdapter da = new DB2DataAdapter(query, conn))
					da.Fill(ds);
			return ds.Tables[0];
		}
		public DataTable ReturnDB2(string sql)
		{
			Database database = DatabaseFactory.CreateDatabase("TCA");
			DbConnection db = database.CreateConnection();
			DbDataAdapter da = database.GetDataAdapter();
			da.SelectCommand = db.CreateCommand();
			da.SelectCommand.CommandText = sql;
			DataSet ds = new DataSet();
			da.Fill(ds);
			da.Dispose();
			db.Close();
			db.Dispose();
			return ds.Tables.Count > 0 ? ds.Tables[0] : null;
		}

	}
}
